import scopt.test.common
from scopt.mpu.business.devel.handlers import mpu_get
from scopt.mpu.business.devel.handlers import mpu_list
from scopt.test.common import DEFAULT_TENANT_ID


class RegistryTest(scopt.test.common.ScoptTest):
    def test_mpu_list(self):
        request = self.request(mpu_list.handle)
        request['reqh']['tenant_id'] = DEFAULT_TENANT_ID
        request['reqd'] = {}
        response = self.send_request(request)
        response_status = response['resh']['status']
        self.assertEqual(response_status, 'OK')

    def test_mpu_get_correct_version(self):
        request = self.request(mpu_get.handle)
        request['reqh']['tenant_id'] = DEFAULT_TENANT_ID
        request['reqd']['message_type'] = 'devel.echo.0.1'
        response = self.send_request(request)
        response_status = response['resh']['status']
        self.assertEqual(response_status, 'OK')

        request = self.request(mpu_get.handle)
        request['reqh']['tenant_id'] = DEFAULT_TENANT_ID
        request['reqd']['message_type'] = 'devel.echo.0.2'
        response = self.send_request(request)
        response_status = response['resh']['status']
        self.assertEqual(response_status, 'OK')

    def test_mpu_get_incorrect_version(self):
        request = self.request(mpu_get.handle)
        request['reqh']['tenant_id'] = DEFAULT_TENANT_ID
        request['reqd']['message_type'] = 'devel.echo.0.3'
        response = self.send_request(request,
                                     pass_interrupts=True)
        response_status = response['resh']['status']
        self.assertEqual(response_status, 'INT')

